package com.yukh.test.javabase.collection.map;

import java.text.CollationKey;
import java.text.Collator;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;

import org.junit.Test;

public class LinkedHashMapDemo {
	@Test
	public void hashMap() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("a3", "aa");
		map.put("a2", "bb");
		map.put("b1", "cc");
		for (Iterator iterator = map.values().iterator(); iterator.hasNext();) {
			String name = (String) iterator.next();
			System.out.println(name);
		}
	}

	@Test
	public void linkedHashMap() {
		Map<String, String> map = new LinkedHashMap<String, String>();
		map.put("a3", "aa");
		map.put("a2", "bb");
		map.put("b1", "cc");
		for (Iterator iterator = map.values().iterator(); iterator.hasNext();) {
			String name = (String) iterator.next();
			System.out.println(name);
		}
		
	}
	
	@Test
	public void treeMap() {
		Map<String, String> map = new TreeMap<String, String>(
				new Comparator<Object>() {
					Collator collator = Collator.getInstance();
					public int compare(Object o1, Object o2) {
						CollationKey key1 = collator.getCollationKey(o1.toString());
						CollationKey key2 = collator.getCollationKey(o2.toString());
						return key1.compareTo(key2);
					}
				});
		map.put("a3", "aa");
		map.put("a2", "bb");
		map.put("b1", "cc");
		for (Iterator iterator = map.values().iterator(); iterator.hasNext();) {
			String name = (String) iterator.next();
			System.out.println(name);
		}
	}
}
